﻿using Bll;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Myproject.BSM.PcWeb.PcChannel.Agency
{
    public partial class AgencyList : System.Web.UI.Page
    {
        #region pageMessage
        //页面输出信息行数
        private string pageSize;

        public string PageSize
        {
            get { return pageSize; }
            set { pageSize = value; }
        }
        //当前页数
        private string pageCurrent;

        public string PageCurrent
        {
            get { return pageCurrent; }
            set { pageCurrent = value; }
        }

        //排序字段
        private string orderField;

        public string OrderField
        {
            get { return orderField; }
            set { orderField = value; }
        }

        //排序
        private string orderDirection;

        public string OrderDirection
        {
            get { return orderDirection; }
            set { orderDirection = value; }
        }

        //总行数
        private long allRecords;

        public long AllRecords
        {
            get { return allRecords; }
            set { allRecords = value; }
        }

        //数据表
        private DataTable messageTable;

        public DataTable MessageTable
        {
            get { return messageTable; }
            set { messageTable = value; }
        }

        #endregion pageMessage
        protected void Page_Load(object sender, EventArgs e)
        {
            //string dos = Request.Params["dos"];
            //if (dos != "no")
            //{
            string cid = Request.Form["pc_Channel_AgencyList_GoodsID"];
            if (string.IsNullOrEmpty(cid))
                cid = Request.Params["cid"];
            string wherestr = " 1=1 ";
            if (!string.IsNullOrEmpty(cid))
            {
                wherestr += " and GoodsID = '" + cid + "' ";
                pc_Channel_AgencyList_GoodsName.Value = new GoodsBLL().GetModel(int.Parse(cid)).Name;
                pc_Channel_AgencyList_GoodsID.Value = cid;
            }
            string aclass = Request.Form["pc_Channel_AgencyList_class"];
            if (!string.IsNullOrEmpty(aclass))
            {
                wherestr += " and AgencyClassName like '%" + aclass + "%' ";
                pc_Channel_AgencyList_class.Value = aclass;
            }
            string wechar = Request.Form["pc_Channel_AgencyList_wechar"];
            if (!string.IsNullOrEmpty(wechar))
            {
                wherestr += " and Wechar like '%" + wechar + "%' ";
                pc_Channel_AgencyList_wechar.Value = wechar;
            }
            string phone = Request.Form["pc_Channel_AgencyList_phone"];
            if (!string.IsNullOrEmpty(phone))
            {
                wherestr += " and phone like '%" + phone + "%' ";
                pc_Channel_AgencyList_phone.Value = phone;
            }

            orderField = Request.Form["orderField"];

            orderDirection = Request.Form["orderDirection"];


            pageCurrent = Request.Form["PageCurrent"] == null ? "1" : Request.Form["PageCurrent"].ToString();
            if (pageCurrent == "") pageCurrent = "1";
            pageSize = Request.Form["pageSize"] == null ? "20" : Request.Form["pageSize"].ToString();
            if (pageSize == "") pageSize = "20";


            AgencyBLL bll = new AgencyBLL();
            int startIndex = (int.Parse(pageCurrent) - 1) * int.Parse(pageSize) + 1;
            int endIndex = int.Parse(pageCurrent) * int.Parse(pageSize);
            messageTable = bll.GetListByPage(wherestr, orderField, orderDirection, startIndex, endIndex).Tables[0];
            allRecords = bll.GetRecordCount(wherestr);
        }
    }
}